import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreAliappConfigService extends BaseService<any> {
  private readonly logger = new Logger(CoreAliappConfigService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getAliappConfig
   * 对应 PHP: CoreAliappConfigService_core::getAliappConfig()
   * 逻辑类型: undefined - undefined
   */
  async getAliappConfig(site_id: number) {
    // 基于PHP真实逻辑: getAliappConfig
    // PHP原文: $info = (new CoreConfigService())->getConfig($site_id, ConfigKeyDict::ALIAPP)['value'] ?? [];         return [             'name' => $info['name'] ?? ...
const info = this.coreConfigService.getConfig(site_id, ConfigKeyDict.ALIAPP).value || [];
        return [
            name: info.name || '',
            app_id: info.app_id || '',
            private_key: info.private_key || '',
            aes_key: info.aes_key || '',
            public_key_crt:  info.public_key_crt || '',
            alipay_public_key_crt:  info.alipay_public_key_crt || '',
            alipay_with_crt:  info.alipay_with_crt || '',
            qrcode: info.qrcode || ''
        ];
    }

    /**
     * 支付宝小程序配置
     * @param int site_id
     * @param data
     * @return SysConfig|bool|Model
     */
    async setAliappConfig(int site_id, data){
        const config = [
            name: data.name || '',
            app_id: data.app_id || '',
            private_key: data.private_key || '',
            aes_key: data.aes_key || '',
            public_key_crt:  data.public_key_crt || '',
            alipay_public_key_crt:  data.alipay_public_key_crt || '',
            alipay_with_crt:  data.alipay_with_crt || '',
            qrcode: data.qrcode || ''
        ];
        return this.coreConfigService.setConfig(site_id, ConfigKeyDict.ALIAPP, config);
    }


}
  }

  /**
   * setAliappConfig
   * 对应 PHP: CoreAliappConfigService_core::setAliappConfig()
   * 逻辑类型: undefined - undefined
   */
  async setAliappConfig(site_id: any[], data: any[]) {
    // 基于PHP真实逻辑: setAliappConfig
    // PHP原文: $config = [             'name' => $data['name'] ?? '',             'app_id' => $data['app_id'] ?? '',             'private_key'            => $data['p...
const config = [
            name: data.name || '',
            app_id: data.app_id || '',
            private_key: data.private_key || '',
            aes_key: data.aes_key || '',
            public_key_crt:  data.public_key_crt || '',
            alipay_public_key_crt:  data.alipay_public_key_crt || '',
            alipay_with_crt:  data.alipay_with_crt || '',
            qrcode: data.qrcode || ''
        ];
        return this.coreConfigService.setConfig(site_id, ConfigKeyDict.ALIAPP, config);
    }


}
  }
}
